<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<title>总部</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.4.5/angular.min.js"></script>
<script src="${pageContext.request.contextPath}/js/MD5.js"></script>

</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>分销佣金设置</span>
					</div>
					<form class="form-horizontal" style="margin-top: 60px">
						<div class="form-group">
							<label class="col-xs-2 control-label" style="text-align: right">一级分销佣金
							</label>
							<div class="col-xs-2">
								<input type="number" id="oneLevel"
									oninput="if(value.length>5)value=value.slice(0,5)"
									class="form-control" placeholder="请输入一级分销佣金">
							</div>
							<label class="col-xs-2 control-label" style="text-align: left">%
							</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label" style="text-align: right">二级分销佣金</label>
							<div class="col-xs-2">
								<input type="number"  id="twoLevel"
									oninput="if(value.length>6)value=value.slice(0,6)"
									class="form-control" placeholder="请输入二级分销佣金">
							</div>
							<label class="col-xs-2 control-label" style="text-align: left">%</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label" style="text-align: right">三级分销佣金</label>
							<div class="col-xs-2">
								<input type="number"  id="threeLevel"
									oninput="if(value.length>6)value=value.slice(0,6)"
									class="form-control" placeholder="请输入三级分销佣金">
							</div>
							<label class="col-xs-2 control-label" style="text-align: left">%</label>
						</div>
						<div class="form-group">
							<div class="col-xs-4 col-xs-offset-2">
								<button type="button" class="col-xs-6 btn btn-primary"
									onclick="submitSet()">点此设置</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</section>
	</div>
	<script>
		$(function() {
			$.post(urls + "utilAction/getCommission",
				function(res) {
					if (res) {
						$("#oneLevel").val(res.oneLevel);
						$("#twoLevel").val(res.twoLevel);
						$("#threeLevel").val(res.threeLevel);
					}
				}
			)
		})
		function submitSet() {
		
			var oneLevel = parseFloat($("#oneLevel").val());
			var twoLevel = parseFloat($("#twoLevel").val());
			var threeLevel = parseFloat($("#threeLevel").val());
			var sum=oneLevel+twoLevel+threeLevel;
			if(sum>80){
			alert("总分成不能大于百分之八十");
			return
			}
			if (oneLevel && twoLevel && threeLevel) {
				$.post(urls + "utilAction/updateCommission",
					{
					    id:1,
	                    oneLevel:oneLevel,
	                    twoLevel:twoLevel,
	                    threeLevel:threeLevel,
					},
					function(data) {
						if (data) {
							alert("设置成功");
						} else {
							alert("设置失败")
						}
					})
			} else {
				alert("请填写完整信息")
			}
		}
	</script>
</body>
</html>